package com.dead.listener;

import com.dead.config.DeadConfig;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class DeadListener {
    //拒绝消息
    @RabbitListener(queues = DeadConfig.REJECT_QUEUE)
    public void queueListener(Message message, Channel channel) throws IOException {
      log.info("收到消息："+new String(message.getBody())+"  拒绝该消息使其进入死信队列");
        //                          消息到唯一标识                             是否重新入队（重新发送到队列中等待被消费）
        channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
    }
    //死信队列消息
    @RabbitListener(queues = DeadConfig.DEAD_QUEUE)
    public void deadQueueListener(Message message, Channel channel){
        log.info("死信队列收到消息："+new String(message.getBody()));
    }

    //消息过期和消息超出队列大小 ， 都需要消息在队列中 ， 所以不对消息进行消费
}
